home *** CD-ROM | disk | FTP | other *** search
- #!/bin/perl
-
- require "cgi-lib.pl";
-
- if (&ReadParse(*input)) {
- print &PrintHeader;
- print "<title> Hangman </title>";
- print "<h1>The Hangman Game ...</h1>";
- if ($input{'done'} eq 'done') # the person guessed the word
- { if ($input{'real'} eq $input{'new'}) # did they get it right?
- {print 'You were right.';}
- else {print 'You were WRONG!<p>';
- print 'It was really ',$input{'real'},'.';}
- print '<p><p>Click <a href="/cgi-bin/nik/hangman-nice.pl">';
- print 'here</a> to play again.';
- return;
- }
- $input{'new'} =~ s/^(.)(.*)/$1/; # only get the 1st char
- $guess = $input{'new'}.' '.$input{'guess'}; # put the new one in $guess
- @sofar = split(/\s+/,$guess); # make guess into an array
- $gue = @sofar;
- $num = length($input{'real'});
- @rreal = split(/ */,$input{'real'}); # make the real word into an array
- # buy splitting on space or nil
- print '<p>';
- print 'So far you have guessed:<p>';
- $gotten = 0;
- LET: for ($i=0;$i<$num;$i++) #go through the real word
- { $temp = $rreal[$i];
- for ($g=0;$g<$gue;$g++) #go through the guesses
- { if ($sofar[$g] eq $temp)
- { print $temp;
- $gotten = $gotten +1;
- next LET;
- }
- }
- print '_ ';
- }
- print '<p>';
- print '<img src="http://blackcat.brynmawr.edu/~nswoboda/scripts/hang',($gue-$gotten),'.gif"><p>';
- if (($gue-$gotten) < 6) {
- print 'Please type your next guess<p>';
- print 'You have ',(6-($gue-$gotten)),' guesse(s) left!<p>';
-
- print <<EOF
- <form method="post" action="/cgi-bin/nik/hangman-nice.pl">
- <input name = "new"><p>
- <input type="hidden" name="guess" value="$guess">
- <input type="hidden" name="real" value="$input{'real'}">
- <INPUT TYPE="reset" VALUE="Clear">
- <input type="submit" value="Continue">
- </form>
- Or if you are daring type in what you think that the word is.<p>
- <form method="post" action="/cgi-bin/nik/hangman-nice.pl">
- <input name="new"><p>
- <input type="hidden" name="done" value="done">
- <input type="hidden" name="real" value="$input{'real'}">
- <INPUT TYPE="reset" VALUE="Clear">
- <input type="submit" value="Guess It">
- </form> </html>
- EOF
- }
- else{
- print <<EOF
- Sorry the game is over.<p>
- The correct answer is $input{'real'}.<p>
- click <a href="/cgi-bin/nik/hangman.pl"> here</a> to play again.
- EOF
- }
- }
- else {
- print &PrintHeader;
- print '<title> Hangman </title>';
- print '<h1> Hangman Game.</h1><br>';
- $real = "first";
- $num = length($real);
- for ($i=1;$i<=$num;$i++)
- { print '_ ';
- }
- print '<p>';
- print '<img src="http://blackcat.brynmawr.edu/~nswoboda/scripts/hang0.gif"><p>';
- print 'Type in your first guess at the above unknown word.<p>';
- print <<EOF
- <form method="post" action="/cgi-bin/nik/hangman-nice.pl">
- <input name = "new"><p>
- <input type="hidden" name="guess" value="">
- <input type="hidden" name="real" value="$real">
- <INPUT TYPE="reset" VALUE="Clear">
- <input type="submit" value="Continue">
- </form>
- Or if you are daring type in what you think that the word is.<p>
- <form method="post" action="/cgi-bin/nik/hangman-nice.pl">
- <input name="new"><p>
- <input type="hidden" name="done" value="done">
- <input type="hidden" name="real" value="$real">
- <INPUT TYPE="reset" VALUE="Clear">
- <input type="submit" value="Guess It">
- </form> </html>
- EOF
- }
-